<?php
/*	header('content-type:text/html;charset=utf8');
	session_start();*/
	require_once 'config.inc.php';
	//看是刷新还是提交过来的登陆
	if(!empty($_POST['gologin']) && $_POST['gologin'] == '登 陆'){
		//直接登陆
		if($_SESSION['ucode'] != $_POST['ucode']){
			die('验证码不正确!');
		}
		$sql = 'select uid,uname,uface from users where uname=? and upwd=?';
		try{ 
			$stmt = $link->prepare($sql);
			$stmt->execute([$_POST['uname'],md5($_POST['upwd'])]);
			//查询出来的结果要么是一行,要么是空
			if($stmt->rowCount() != 1){
				die('用户名或密码不正确!');
			}else{
				$row = $stmt->fetch(PDO::FETCH_ASSOC);
				$_SESSION['uid'] = $row['uid'];
				$_SESSION['uname'] = $row['uname'];
				$_SESSION['uface'] = $row['uface'];
				//echo '登陆成功!'
				header('location:index.php');//登陆成功跳转到主页
				//echo '登陆成功!';
			}
			
		}catch(PDOException $e){
			die('用户登陆查询出错:'.$e->getMessage());
		}
		
		
	}

?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>多用户博客</title>
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
	</head>
	<body>
		<?php include_once 'header.php';  ?>
		<div id="body"> 
			<div id="reg">
				<form action="login.php" method="post">
					<table border="0" cellspacing="10" cellpadding="0">
						<!--<colgroup>
							<col width="100" align="right"/>
							<col width="500"/>
						</colgroup>-->
						
						<tr>
							<td class="right">用户名:</td>
							<td><input placeholder="请输入2位以上用户名" type="text" name="uname" value="" /></td>
						</tr>
						<tr>
							<td class="right">密码:</td>
							<td><input placeholder="请输入6位以上密码" type="password" name="upwd" value="" /></td>
						</tr>
						<tr>
							<td class="right">验证码:</td>
							<td>
								<input type="text" name="ucode" value="" style="width: 60px;" />
								<img src="gdcode.php" onclick="this.src='gdcode.php?'+Math.random();" style="vertical-align: top;"/>
								
								</td>
						</tr>
						<tr>
						<tr>
							<td class="right"></td>
							<td>
								<input type="button" value="找回密码"/>
								<input type="submit" name="gologin" value="登 陆"/>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
			<!--<embed type="application/x-shockwave-flash" src="img/hamster.swf" width="280" height="210" id="flashID" name="flashID" bgcolor="#ccc" quality="high" flashvars="up_backgroundColor=FFFFFF" wmode="opaque" allowscriptaccess="always">-->
		<!--网站底部,写好后提取到单独页面-->
		<?php include 'bottom.php';  ?>
		
	</body>
</html>
